package com.zygh.lz.controller;

import com.alibaba.fastjson.JSONObject;
import com.zygh.lz.entity.Gps;
import com.zygh.lz.entity.Location;
import com.zygh.lz.service.LocationService;
import com.zygh.lz.stapprove.InBean;
import com.zygh.lz.vo.ResultBean;
import io.swagger.annotations.ApiOperation;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
public class LocationController {
    @Autowired
    private LocationService locationService;

    @PostMapping("addLocation")
    public ResultBean addLocation(@Valid Location location, @RequestBody(required = false) InBean inBean) {
        JSONObject jsonObject = inBean.convertObj(JSONObject.class);
        location.setStaffid(Integer.valueOf(jsonObject.getString("staffid")))
                .setLongitude(jsonObject.getString("Longitude"))
                .setLatitude(jsonObject.getString("Latitude"))
                .setWarningSignal(jsonObject.getString("warningSignal"))
                .setDirection(jsonObject.getString("Direction"))
                .setDistrict(jsonObject.getString("District"))
                .setTown(jsonObject.getString("Town"))
                .setSpeed(jsonObject.getString("Speed"))
                .setLocationDescribe(jsonObject.getString("LocationDescribe"));
        return locationService.addLocation(location);
    }

//    @PostMapping("addLocations")
//    public ResultBean addLocation(@RequestBody Location location) {
//        return locationService.addLocation(location);
//    }


    @GetMapping("delLocation")
    public ResultBean delLocation(Integer id) {
        return locationService.delLocation(id);
    }

    @ApiOperation("下属实时位置")
    @GetMapping("subordinatePosition")
    public ResultBean subordinatePosition(Integer id) {
        return locationService.subordinatePosition(id);
    }



}
